package com.xmy.jmm;

import java.util.concurrent.TimeUnit;

public class JMMTest {
    private  static  int num = 0;

    public synchronized static void add(){
        num++;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                for (int i1 = 0; i1 < 1000; i1++) {
                    add();
                }
            }).start();
        }

        while (Thread.activeCount()>2) { // java程序中始终存在的两个线程 main和gc
            Thread.yield();
        }
        System.out.println(Thread.currentThread().getName() + " " + num);
    }
}
